<?php

namespace app\admin\model;

use think\Model;

class Role_node extends Model
{
    public function add($rid,$nid=[])
    {
        $list = [];
        if (is_array($nid)){
            foreach ($nid as $val){
                $list[] = ['rid'=>$rid ,'nid'=>$val];
            }

           $this->saveAll($list);
            return 1;
        }
        return 0;
    }


    public static function allNid($rid)
    {
        $where = function ($query) use ($rid){
            $query->field(['nid'])->where(['rid'=>$rid]);
        };
        $arr = parent::all($where);
        $nid = [];
        foreach ($arr as $val){
            $nid[] = $val->getData()['nid'];
        }
        return $nid;
    }


}
